package com.hong.strategy.rpcserver;

import com.hong.Config.ConfigManager;
import com.hong.RpcServer;
import com.hong.config.constant.ServerConfig;
import com.hong.listener.impl.RpcServerConfigurer;
import com.hong.qrpc.utils.StringUtils;
import com.hong.strategy.PropertiesStrategy;

import java.util.Map;

/**
 * @Author HQT
 * @Date 2022/7/17 14:42
 */
public class PortStrategy implements PropertiesStrategy {
    @Override
    public void disposeProperties(RpcServer rpcServer) {
        ConfigManager configManager = rpcServer.getConfigManager();
        Map<Object, Object> profile = configManager.getProfile();
        String port = (String) profile.get(ServerConfig.QRPC_SERVER_PORT);
        if (!StringUtils.isEmpty(port)) {
            configManager.getRpcServerConfig().setPort(Integer.parseInt(port));
            RpcServerConfigurer.addListener(rpcServer.getListenerManager());
        }
    }
}
